package model

import (
	"erp/app"
	"log"
)

type User struct {
	Id         int     `json:"id" xorm:"not null pk autoincr INT(11)"`
	Username   string  `json:"username"`
	Name       string  `json:"name"`
	OrgName    string  `json:"org_name"`
	Password   string  `json:"password"`
	CreateTime string  `json:"create_time" xorm:"Created"`
	Balance    float64 `json:"balance"`
}

func (u User) Get(id int) User {
	var engine = app.GetDbEngine()

	_, err := engine.Table("f_admin_user").Where("id=?", id).Get(&u)
	if err != nil {
		log.Panic(err)
	}

	return u
}

func (u User) GetByUsername(username string) User {
	var engine = app.GetDbEngine()

	_, err := engine.Table("f_admin_user").Where("username=?", username).Get(&u)
	if err != nil {
		log.Panic(err)
	}

	return u
}
